package xycdao

import (
	"Cgo/backend/models"
	"Cgo/global"
)

type xycAddressDao struct{}

var XycAddressDao = xycAddressDao{}

// 根据id查询地址,不传id则查询所有地址
func (xycAddressDao) FindAddressByIdDao(address models.XycAddress) ([]models.XycAddress, error) {
	var addresses []models.XycAddress
	if r := global.DB.Where(&address).Find(&addresses); r.Error != nil {
		return addresses, r.Error
	} else {
		return addresses, nil
	}
}

// 添加地址
func (xycAddressDao) AddAddressDao(address models.XycAddress) error {
	if r := global.DB.Create(&address); r.Error != nil {
		return r.Error
	} else {
		return nil
	}
}

// 删除地址
func (xycAddressDao) DeleteAddressDao(address models.XycAddress) error {
	if r := global.DB.Delete(&address); r.Error != nil {
		return r.Error
	} else {
		return nil
	}
}

// 更新地址
func (xycAddressDao) UpdateAddressDao(address models.XycAddress) error {
	if r := global.DB.Save(&address); r.Error != nil {
		return r.Error
	} else {
		return nil
	}
}
